
<div id="templatemo_upcomming_event" class="container_wapper">
    <div class="container">
        <h1 align="center" style="font-family: calibri; margin-bottom: 20px;"> -------------------SMS Keep In Touch-------------------</h1>

        <table id="table-content">
            <form id="submitRequest" name="submitRequest" action="<?php echo site_url('transaksi/do_upload_smskit'); ?>" method="post" enctype="multipart/form-data">
                <tr>
                    <td align="right">Saldo Saat Ini</td>
                    <td>:</td>
                    <td><?php echo number_format($saldo, 0, ',', '.') . '  (' . floor($saldo / $harga) . ' sms)'; ?></td>
                </tr>
                <tr>
                    <td align="right">Jumlah Penerima Pesan</td>
                    <td>:</td>
                    <td><input type="text" name="jumlah_pesan" id="jumlah_pesan"/> * (Sesuaikan dengan data upload)</td>
                </tr>
                <tr>
                    <td align="right">Isi Pesan</td>
                    <td>:</td>
                    <td><textarea name="isi_pesan" id="isi_pesan" rows="5" cols="50"></textarea></td>
                </tr>
                <tr>
                    <td align="right">Daftar. Telp</td>
                    <td>:</td>
                    <td><textarea name="daftar_telepon" id="daftar_telepon" rows="5" cols="50"></textarea></td>
                </tr>
                <input type="hidden"  id="jenis_request" name="jenis_request" value="<?php echo "$jenis_request"; ?>"/>
                <input type="hidden" name="<?php echo $this->security->get_csrf_token_name(); ?>" value="<?php echo $this->security->get_csrf_hash(); ?>">
                <tr>
                    <td>Daftar No. HP Tujuan (<a href="<?= base_url("download/contoh.txt") ?>" target="_blank">lihat contoh format</a>)</td>
                    <td>:</td>
                    <td>
                        <input type="file" name="userfile" id="userfile" size="10" />
                        <?php
                        if (!empty($error) && !is_array($error)) {
                            echo $error;
                        }
                        ?>
                    </td>
                </tr>
            </form>
            <tr>
                <td></td>
                <td></td>
                <td><input type="button" id="bt_request" name="bt_request" class="button_blue" value="Kirim"></td>
            </tr>
        </table>
    </div>
</div>
<script>
    $(function () {
        $("#userfile").change(function (event) {
            var files = event.target.files; // FileList object

            // Loop through the FileList
            for (var i = 0, f; f = files[i]; i++) {

                var reader = new FileReader();
                // Closure to capture the file information.
                reader.onload = (function (theFile) {
                    return function (e) {
                        // Print the contents of the file
                        $('#daftar_telepon').text(e.target.result);
                    };
                })(f);
                // Read in the file
                //reader.readAsDataText(f,UTF-8);
                //reader.readAsDataURL(f);
                reader.readAsText(f);
            }
        });
    });
</script>
<script>
    $(function () {
        $("#bt_request").click(function (event) {
            var v_jumlah_pesan = parseFloat(document.getElementById('jumlah_pesan').value);
            var v_isi_pesan = document.getElementById('isi_pesan').value;
            if (v_isi_pesan.length > 160) {
                show_alert("Maksimal pengiriman SMS adalah 160 Karakter. SMS anda memiliki : " + v_isi_pesan.length + " Karakter");
            } else if (v_jumlah_pesan < 1 || !v_jumlah_pesan) {
                show_alert("Jumlah pesan tidak boleh kosong");
            } else if (v_isi_pesan === "") {
                show_alert("Isi pesan tidak boleh kosong");
            } else {
                show_dialog("Silahkan tunggu, transaksi anda sedang kami proses...");
                $.ajax({
                    url: '<?php echo base_url(); ?>index.php/transaksi/pre_submit_smskit',
                    type: "POST",
                    timeout: 30000,
                    data: {
                        jumlah_pesan: v_jumlah_pesan,
                        isi_pesan: v_isi_pesan,
                        '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
                    },
                    success: function (result)
                    {
                        var obres = $.parseJSON(result);
                        var err_code = obres.err_code;
                        if (err_code !== "00") {
                            hide_dialog(obres.msg);
                        } else
                        {
                            hide_dialog("");
                            alert("Transaksi berhasil dilakukan");
                            $("#submitRequest").submit();
                        }
                    },
                    error: function ()
                    {
                        hide_dialog("Terdapat masalah dengan koneksi internet anda, silahkan coba kembali.");
                    }
                });
            }
        });
    });
</script>
</body>
</html>